package org.vectrics.recruiter.struts.admin;

import org.apache.log4j.Category;
import org.apache.struts.action.ActionForm;
import org.vectrics.domain.Domain;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;


public class ShowSystemConfigurationEditAction extends VectricsStrutsAction {
    private static Category log = Category.getInstance(ShowSystemConfigurationEditAction.class);
	public static String JOB_PARAM = "job";
	

	// Intercept 
	public String doExecute(VectricsActionData actionData) {
		ActionForm form = actionData.getForm();
		Request request = actionData.getRequest();
		//boolean authorized = false;
		Person authPerson = actionData.getAuthPerson();

		log.debug("execute() called");
		String forward = "success";
		
		Domain domain = ThreadProperties.getDomain();
		ConfigurationForm configForm = (ConfigurationForm)form;
		if (form == null) {
			log.debug("execute() - form is null, creating...");
			configForm = new ConfigurationForm();
		}
		else {
			log.debug("execute() - form is NOT null, casting to AdminJobForm in order to write properties");
			configForm = (ConfigurationForm)form;
		}
		configForm.setDomainId(ThreadProperties.getDomain().getId().toString());
		configForm.setResumeEmailAddress(CoreServiceLocator.getSystemService().findSystemConstant(domain, "resume.recipient.email.addr").getValue());
		configForm.setResumeEmailHost(CoreServiceLocator.getSystemService().findSystemConstant(domain, "resume.recipient.email.host").getValue());
		configForm.setResumeEmailPassword(CoreServiceLocator.getSystemService().findSystemConstant(domain, "resume.recipient.email.password").getValue());
		
		actionData.setRequestForm(configForm);
		return (forward);
	}
	
	
}
